﻿using AutoMapper;
using Pay.Data;
using Pay.DTO;
using Pay.Core;
using Pay.IService;
using System.Collections.Generic;

namespace Pay.Service.AutoMapper {
	public class MerchantPaymentMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public MerchantPaymentMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<merchant_payment_dto, MerchantPayment>()
				.ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
				.ForMember(dest => dest.PaymentId, src => src.MapFrom(c => c.payment_id))
				.ForMember(dest => dest.Settles, src => src.MapFrom(c => c.settles.ToJson()))
				.ForMember(dest => dest.Payment, src => src.Ignore());
			_cfg.CreateMap<MerchantPayment, merchant_payment_dto>()
				.ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
				.ForMember(dest => dest.payment_id, src => src.MapFrom(c => c.PaymentId))
				.ForMember(dest => dest.settles, src => src.MapFrom(c => c.Settles.ToObject<List<settle_setting>>()));
		}
	}
}
